<!--
 * @Author: 弗兰克 1085068573@qq.com
 * @Description: 登录组件-账号/手机登录
-->
<template>
  <div class="login-panel">
    <h1 class="title">组件库后台系统</h1>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 账号登录</span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i>手机登录</span>
        </template>
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { TabsPaneContext } from 'element-plus'
import LoginAccount from './login-account.vue'
// 定义属性
const isKeepPassword = ref(true)
const activeName = ref('account')
const accountRef = ref<InstanceType<typeof LoginAccount>>()
/**
 * @description: el-tabs点击进行切换事件
 */
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
}
/**
 * @description: el-tabs点击进行切换事件
 */
const handleLoginClick = () => {
  if (activeName.value === 'account') {
    // console.log('accountRef====', accountRef.value)
    // console.log('isKeepPassword==', isKeepPassword.value)
    accountRef.value?.loginAction(isKeepPassword.value)
  } else {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 150px;

  .title {
    text-align: center;
  }
}
.account-control {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}
.login-btn {
  width: 100%;
  margin-top: 10px;
}
</style>
